import player
import pygame
import map
import account
import config
import test

players = []
view_size = 2
radius = 50

def add_player(screen):
    cur_player = player.new_player(screen)
    cur_player.start()
    players.append(cur_player)

def draw_pos(player, screen):
    player_map = map.get_data(player)
    x = player_map.x
    y = player_map.y
    if x >= 0 and y >= 0:
        draw_surface = pygame.Surface((config.get_screen_x(), config.get_screen_y()), pygame.SRCALPHA)
        player_account = account.get_data(player)
        
        opp_x = (2 * view_size + 1) * radius
        opp_y = opp_x

        length = 2 * opp_x
        height = length

        pygame.draw.rect(draw_surface, (255, 255, 255, 20), ((x - opp_x, y - opp_y), (length, height)), radius)
        pygame.draw.circle(draw_surface, (255, 0, 0, 50), (x, y), 50)
        uid_font = pygame.font.SysFont('Courier', 15)
        uid_text = uid_font.render(str(player_account.uid), False, (0, 0, 0))
        draw_surface.blit(uid_text, (player_map.x - 20, player_map.y - 5))
        screen.blit(draw_surface, (0, 0))   

def main():
    pygame.init()
    screen = pygame.display.set_mode((config.get_screen_x(), config.get_screen_y()))
    
    pygame.display.set_caption('tower_aoi')
    # screen.fill((160, 200, 220))
    running = True
    while running:
        bg_color = (160, 200, 220)
        screen.fill(bg_color)
        for acc_player in players:
            draw_pos(acc_player, screen)
            
        for acc_player in players:
            # 每隔几秒随机走动一下
            test.ramdom_move(acc_player)   

        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:    
                if event.key == pygame.K_UP:
                    add_player(screen)


     
    

if __name__ == '__main__':
    main()


